class CreateWeblogs < ActiveRecord::Migration
  def self.up
    create_table :weblogs do |t|
      t.column :lock_version,     :integer,   :null  => false
      t.column :name,             :string,    :null  => false, :limit   => 50
      t.column :description,      :string,    :limit => 50
      t.column :categories_count, :integer,   :null  => false, :default => 0
      t.column :albums_count,     :integer,   :null  => false, :default => 0
      t.column :created_at,       :timestamp, :null  => false
      t.column :updated_at,       :timestamp, :null  => false
    end

    add_index :weblogs, :name, :unique => true

    create_table :users_weblogs, :id => false do |t|
      t.column :user_id,   :integer, :null => false
      t.column :weblog_id, :integer, :null => false
    end

    add_index :users_weblogs, [ :user_id, :weblog_id ], :unique => true
  end

  def self.down
    drop_table :users_weblogs
    drop_table :weblogs
  end
end
